import 'package:flutter/cupertino.dart';

/**
 * 投保历史
 */
import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:xiongmao_clean_flutter_module/res/gaps.dart';

import '../../../../widgets/custom_switch.dart';
import '../item/Insure_history_listview.dart';
import '../item/Insure_listview.dart';

/**
 * 保险商城
 */
class InsureHistoryPage extends StatefulWidget {
  @override
  _InsureHistoryPageState createState() => _InsureHistoryPageState();
}

class _InsureHistoryPageState extends State<InsureHistoryPage> {
  List<String> tagList = ['全部', '已过期', '近7天过保'];

  double _getTagWidth(BuildContext context, {int rowCount = 3, double padding = 32.0, double rowItemSpace = 0.0}) {
    double totalWidth = MediaQuery.of(context).size.width - padding; // 考虑左右边距
    double effectiveWidth = totalWidth - (rowCount - 1) * rowItemSpace; // 考虑标签之间的间距

    return (effectiveWidth - 1 * padding) / rowCount; // 减去两侧padding
  }

  @override
  Widget build(BuildContext context) {
    // return InsureListView();
    return SingleChildScrollView(
      child: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              color: Colors.white,
              padding: EdgeInsets.only(right: 16.0, left: 16.0, top: 10.0, bottom: 10.0),
              child: Column(
                children: [
                  //搜索栏
                  Row(
                    children: [
                      Expanded(
                        child: Container(
                          height: 40, // 调整搜索框高度
                          decoration: BoxDecoration(
                            color: Colors.grey[200],
                            borderRadius: BorderRadius.all(Radius.circular(8.0)),
                          ),
                          child: Padding(
                            padding: EdgeInsets.only(left: 8, right: 8),
                            child: TextField(
                              style: TextStyle(fontSize: 13), // 调整输入框的文字大小
                              decoration: InputDecoration(
                                hintText: '请输入员工姓名',
                                border: InputBorder.none,
                              ),
                            ),
                          ),
                        ),
                      ),
                      Gaps.hGap4,
                      Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.0),
                          border: Border.all(color: Colors.green, width: 1.0),
                        ),
                        child: Padding(
                          padding: EdgeInsets.symmetric(horizontal: 6.0, vertical: 6.0),
                          child: Text('理赔记录10', style: TextStyle(color: Colors.green)),
                        ),
                      ),
                      Gaps.hGap4,
                      Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.0),
                          border: Border.all(color: Colors.green, width: 1.0),
                        ),
                        child: Padding(
                          padding: EdgeInsets.symmetric(horizontal: 6.0, vertical: 6.0),
                          child: Text('理赔流程', style: TextStyle(color: Colors.green)),
                        ),
                      ),
                    ],
                  ),
                  Gaps.vGap10,
                  //单选的 tag
                  BrnSelectTag(
                      tags: tagList,
                      spacing: 12,
                      tagWidth: _getTagWidth(context),
                      initTagState: [true],
                      onSelect: (selectedIndexes) {
                        BrnToast.show(selectedIndexes.toString(), context);
                      }),
                  Gaps.vGap10,
                  //筛选条件
                  Row(
                    children: [
                      Expanded(
                        child: Container(
                          child: Row(
                            children: [
                              Text(
                                '隐藏无效人员及保单',
                                style: TextStyle(fontSize: 10.0),
                              ),
                              Gaps.hGap4,
                              CustomSwitch(
                                value: true,
                                onChanged: (value) {},
                                size: 28.0, // 设置Switch的大小
                              ),
                            ],
                          ),
                        ),
                      ),
                      Gaps.hGap10,
                      Expanded(
                        child: Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              Text(
                                '购买时间最近的排前',
                                style: TextStyle(fontSize: 10),
                              ),
                              // Image.asset('assets/index.png', width: 10, height: 10), // 添加下标图片
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
            InsureHistoryListView(),
          ],
        ),
      ),
    );
  }
}
